import hashlib, time, requests, sqlite3


def signStr():
    now_time = str(time.time()).split('.')[0]
    # print(now_time)
    # 创建md5对象
    md5 = hashlib.md5()
    sign_str = now_time + '&Guest-Bugmaster'
    # print(sign_str)
    sign_bytes_utf8 = sign_str.encode()
    # 生成加密串
    md5.update(sign_bytes_utf8)
    # 获取加密串
    sign_md5 = md5.hexdigest()
    return now_time, sign_md5


now_time, signStr = signStr()
print(now_time, signStr)

name = '苹果手机发布会'
url = 'http://127.0.0.1:8000/api/sec_add_event/'
data = {'eid': 16, 'name': name, 'limit': 300, 'address': 'libao', 'start_time': '2018-01-12 12:00:00',
        'time': now_time, 'sign': signStr}
r = requests.post(url, data=data)
print(r.json())


def signStr(sign_str):
    # 创建md5对象
    md5 = hashlib.md5()
    # print(sign_str)
    sign_bytes_utf8 = sign_str.encode()
    # 生成加密串
    md5.update(sign_bytes_utf8)
    # 获取加密串
    sign_md5 = md5.hexdigest()
    return sign_md5

# print(signStr('123456'))


# def exeSql(sql):
#     # 连接到SQLite数据库
#     # 如果文件不存在，会自动在当前目录创建
#     conn = sqlite3.connect(r'E:\Workspace\08-课件\07-接口测试\02 参考资料\guest\db.sqlite3')
#     cursor = conn.cursor()      # 创建一个Cursor
#     try:
#         cursor.execute(sql)      # 执行一条SQL语句
#         results = cursor.fetchall()      # 获得查询结果集
#         cursor.close()      # 关闭Cursor
#         conn.commit()       # 提交事务
#         return results
#     except:
#         conn.rollback()
#     conn.close()        #关闭Connection
#
# sql = 'DELETE FROM sign_event WHERE name = \'%s\';'%name
# exeSql(sql)
